// pages/suspiciousDetail/suspiciousDetail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop:0,
    fileList:[],
    logistics_id: '',
    post_communicate_name: '',
    post_communicate_mobile: '',
    post_communicate_address: '',
    receive_communicate_name: '',
    receive_communicate_mobile: '',
    receive_communicate_address: '',
    arrive_region_name: '',
    goods_type: '',
    weight: '',
    num: '',
    sender_pictures_urls: '',
    get_pictures_urls: '',
    detailInfo: {},
    company_type: 0             //企业类型；0：物流、1：快递
  },
  beforeRead(event) {
    const { file, callback } = event.detail;
    callback(file.type === 'image');
  },
  afterRead(event) {
    let that = this;
    const { file } = event.detail;
    console.log(file)
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      url: wx.$config.uploadFile, // 仅为示例，非真实的接口地址
      filePath: file.url,
      name: 'file',
      formData: { user: 'test' },
      success(res) {
        // 上传完成需要更新 fileList
        let get_data = JSON.parse(res.data);
        const { fileList = [] } = that.data;
        fileList.push({ ...file, url: get_data.data.url });
        console.log(res.data, fileList)
        that.setData({ fileList });
      }
    });
  },
  // 标记可疑
  markSuspicious(e){
    let fileList = this.data.fileList.map(item=>{
      return item.path
    })
    let data={
      logistics_id: this.data.logistics_id,
      pictures_urls: fileList.join(',')
    }
    wx.$api.markSuspicious(data).then(res=>{
      console.log(res.data.data)
      if(res.data.code == 200){
        wx.redirectTo({
          url: '/pages/suspicious/suspicious',
        })
      }else{
        wx.$Toast(res.data.msg)
      }
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      logistics_id: options.id,
      company_type: wx.getStorageSync('user_infos').company_type
    })
    wx.$api.getDetailLogistics({
      logistics_id: options.id
    }).then(res=>{
      console.log(res)
      if(res.data.code == 200){
        let {
          post_communicate_name,
          post_communicate_mobile,
          post_communicate_address,
          receive_communicate_name,
          receive_communicate_mobile,
          receive_communicate_address,
          arrive_region_name,
          goods_type,
          weight,
          num,
          member_pictures,
          employee_pictures
        } = res.data.data || {}
        this.setData({
          post_communicate_name: post_communicate_name,
          post_communicate_mobile: post_communicate_mobile,
          post_communicate_address: post_communicate_address,
          receive_communicate_name: receive_communicate_name,
          receive_communicate_mobile: receive_communicate_mobile,
          receive_communicate_address: receive_communicate_address,
          arrive_region_name: arrive_region_name,
          goods_type: goods_type,
          weight: weight,
          num: num,
          sender_pictures_urls: member_pictures.length ? member_pictures[0]:'',
          get_pictures_urls: employee_pictures.length? employee_pictures[0]:'',
          detailInfo: res.data.data
        })
      }else{
        wx.$Toast
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
